package com.edu.service.impl;

import com.edu.bean.User;
import com.edu.mapper.UserMapper;
import com.edu.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public Map<String, Object> login(User user) {
        Map<String,Object> map = new HashMap<>();
        User user1 = userMapper.selectUserByUserName(user.getUserName());
        if (user1 != null) {
            if (user1.getUserPass().equals(user.getUserPass())) {
                map.put("user",user1);
            } else {
                map.put("msg","密码错误");
            }
        } else {
            map.put("msg","账户不存在");
        }
        return map;
    }


    @Override
    public int register(User user) {
        int row = 0;
        if (userMapper.selectUserByUserName(user.getUserName()) == null) {
            if(userMapper.insertUser(user) > 0){
                row = 1;
            } else {
                row = 0;
            }
        } else {
            row = -1;
        }
        return row;
    }
}
